#include "SpecialEffectManager.h"
#include "RenderManager.h"
#include "Effect.h"

SpecialEffectManager::SpecialEffectManager(void)
{
}


SpecialEffectManager::~SpecialEffectManager(void)
{
}

SpecialEffectManager* SpecialEffectManager::_instance = nullptr;

SpecialEffectManager* SpecialEffectManager::getSingletonPtr()
{
	if (_instance == nullptr)
	{
		_instance = new SpecialEffectManager();
	}
	return _instance;
}

void SpecialEffectManager::cleanSingleton()
{
	if (_instance != nullptr)
	{
		delete _instance;
		_instance = nullptr;
	}
}

void SpecialEffectManager::draw(RenderManager* rm)
{
	for (auto it = _effects.begin(); it != _effects.end(); it++)
	{
		(*it)->draw(rm);
	}
}

void SpecialEffectManager::update()
{
	if (!_remove.empty())
	{
		for (auto it = _remove.begin(); it != _remove.end(); it++)
		{
			_effects.remove((*it));
			delete *it;
		}
		_remove.clear();
	}

	for (auto it = _effects.begin(); it != _effects.end(); it++)
	{
		(*it)->update();
		if ((*it)->killMe())
			_remove.push_back((*it));
	}
}

bool SpecialEffectManager::checkForEffects()
{
	if (!_effects.empty())
		return true;
	return false;
}